import {computed} from 'vue'

export default function (props, name, emit) {
  return computed({
    get() {
      return new Proxy(props[name], {
        get(...args) {
          return Reflect.get(...args)
        },
        set(target, key, value) {
          emit(`update:${name}`, {
            ...target,
            [key]: value
          })
          return true
        }
      })
    },
    set(value) {
      emit(`update:${name}`, value)
    }
  })
}
